package com.shanzmoo.db.store.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.shanzmoo.base.exception.StoreException;
import com.shanzmoo.db.store.entity.StorePurchaseBillEntity;
import com.shanzmoo.db.store.entity.StorePurchaseSupplierEntity;
import com.shanzmoo.db.store.entity.vo.StorePurchaseSupplierVO;
import com.shanzmoo.db.store.entity.query.StorePurchaseSupplierQuery;
import com.shanzmoo.db.store.mapper.StorePurchaseSupplierMapper;
import com.shanzmoo.db.store.service.IStorePurchaseBillDetailService;
import com.shanzmoo.db.store.service.IStorePurchaseBillService;
import com.shanzmoo.db.store.service.IStorePurchaseSupplierService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 仓库采购供应商 服务实现类
 *
 * @author xueqz 2021-03-03
 */
@Service
public class StorePurchaseSupplierServiceImpl extends ServiceImpl<StorePurchaseSupplierMapper, StorePurchaseSupplierEntity>
        implements IStorePurchaseSupplierService {

    @Autowired
    private IStorePurchaseBillService storePurchaseBillService;

    @Override
    public List<StorePurchaseSupplierVO> queryPageList(StorePurchaseSupplierQuery query) {
        return baseMapper.queryPageList(query);
    }

    @Override
    public void deleteById(Integer id) {
        //todo 判断是否有生效的采购订单勾选了
        Boolean mark = storePurchaseBillService.judgeDelSupplier(id);
        if(mark){
            throw new StoreException("已生成有效采购订单,不允许删除供应商");
        }
        StorePurchaseSupplierEntity entity = new StorePurchaseSupplierEntity();
        entity.setId(id);
        entity.setDeleted(true);
//        entity.setUpdateUser(CurrentUserCache.getUserId());
        this.baseMapper.updateById(entity);
    }
}
